package com.yxsd.service.impl;

import com.pandawork.core.exception.SSException;
import com.pandawork.core.log.LogClerk;
import com.pandawork.core.util.Pagination;
import com.yxsd.common.entity.Member;
import com.yxsd.common.exception.YxsdException;
import com.yxsd.common.service.impl.BaseServiceImpl;
import com.yxsd.mapper.MemberMapper;
import com.yxsd.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * MemberServiceImpl
 *
 * @author: zhangteng
 * @time: 2015/1/4 19:12
 */
@Service("memberService")
public class MemberServiceImpl extends BaseServiceImpl implements MemberService {

    @Autowired
    private MemberMapper memberMapper;

    @Override
    public List<Member> queryByCondition(Pagination page, String search) throws SSException {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            int pCurrent = 0, pSize = 10;
            if (page != null) {
                pCurrent = page.getCurrentFristPosition();
                pSize = page.getPageSize();
            }
            params.put("pCurrent", pCurrent);
            params.put("pSize", pSize);
            params.put("search", search);
            List<Member> memberList = memberMapper.queryByCondition(params);
            return memberList;
        } catch (Exception e) {
            LogClerk.errLog.error(e);
            throw SSException.get(YxsdException.SystemException, e);
        }
    }

    @Override
    public int queryCountByCondition(String search) throws SSException {
        try {
            return memberMapper.queryCountByCondition(search);
        } catch (Exception e) {
            LogClerk.errLog.error(e);
            throw SSException.get(YxsdException.SystemException);
        }
    }
}
